package com.thoughtworks.conference.view;

import com.thoughtworks.conference.constants.CommonConstants;
import com.thoughtworks.conference.constants.SystemMessageConstants;
import com.thoughtworks.conference.controller.ConferenceTrackMangentController;
import com.thoughtworks.conference.exception.ConferenceTrackException;

import java.util.Scanner;

/**
 * <p>Title: </p>
 * <p>Description:</p>
 *
 * @author <a href="mailTo:bingxuewulei@outlook.com">wanglei</a>
 * @version 1.0
 * @history: Created by wanglei on  2019/4/23
 */
public class MenuMain {
    ConferenceTrackMangentController conferenceTrackMangentController = new ConferenceTrackMangentController();

    private MenuMain() {
    }

    /**
     * 获取系统菜单实例
     *
     * @return
     */
    public static MenuMain getInstanceMenuMain() {
        return new MenuMain();
    }


    /**
     * 显示系统的菜单
     */
    public void displaySystemView() {
        String userInput = null;
        while (!CommonConstants.EXIT_FLAG.equals(userInput)) {
            System.out.println(SystemMessageConstants.MESSAGE_INPUT_TIP);
            Scanner scn = new Scanner(System.in);
            userInput = scn.nextLine();
            if (!CommonConstants.EXIT_FLAG.equals(userInput)) {
                //路径校验通过，处理数据文件
                try {
                    conferenceTrackMangentController.dealConferenceTrack(userInput);
                } catch (ConferenceTrackException e) {
                    System.err.println(e.getMessage());
                }
            }else{
                System.out.println(SystemMessageConstants.MESSAGE_EXIT);
            }
        }
    }
}
